/**
 * 
 */
package com.czmh.etc.interpreter.controller;

import com.czmh.etc.interpreter.entity.InterpreterResponse;
import com.czmh.etc.interpreter.services.IReceiveService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.*;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @描述：
 * @author： Seven.
 * @创建日期：Apr 15, 2019 10:01:50 PM.
 * @版本：1.0.0
 */
@RestController
@RequestMapping("/Interpreter")
public class InterpreterController {

    public Logger logger = LoggerFactory.getLogger(InterpreterController.class);

    @Autowired
    public IReceiveService receiveService;

    @PostMapping(value = "/sendData/{reportType}")
    public String sendData2YiGou(@PathVariable("reportType") String reportType, @RequestBody String JSONStr) throws JsonProcessingException {
        logger.info("进入了InterpreterController的sendData2YiGou方法！传入数据为[reportType:\"" + reportType + "\", JSONStr:\"" + JSONStr + "\"]");

        ObjectMapper om = new ObjectMapper();
        InterpreterResponse response = null;
        Integer reportType_N = null;

        try {
            reportType_N = Integer.parseInt(reportType);
        }catch (Exception exp){
            exp.printStackTrace();

            logger.info("[InterpreterController - sendData2YiGou] 传入参数有误！");
            response = new InterpreterResponse();
            response.setSuccess(false);
            response.setErrorMsg("reportType传入参数有误！");
            return om.writeValueAsString(response);
        }

        response = receiveService.receiveMsgTypeContent(reportType_N, JSONStr);

        return om.writeValueAsString(response);
    }
}
